import MD5 from 'md5'
import { tokenStorageKey, mapTokenStorageKey, telphoneStorageKey, userNameStorageKey } from 'common/js/config'
import { getStorage } from 'common/js/utils'

const hostname = location.hostname

export let HttpUrl = ''
export let LoginUrl = ''
export let mapServiceIp = ''
export let mapGeoserverIp = ''
export let mapTokenIp = ''

// 判断 IP 去改变接口地址
switch (hostname) {
  case '19.130.169.133':
    LoginUrl = `http://19.130.169.126/fszhsl/#/login`
    HttpUrl = `http://19.130.169.133/webDataApi`
    mapServiceIp = 'http://19.130.169.133/environment/gis'
    mapGeoserverIp = 'http://19.130.169.133/environment/gis/gis-proxy/proxy/fsprod1'
    mapTokenIp = 'http://19.130.169.133/environment/gis/gis-proxy/token/accessToken'
    break
  case '19.130.169.82':
    LoginUrl = `http://19.130.169.64/fszhsl/#/login`
    HttpUrl = `http://19.130.169.82/webDataApi`
    mapServiceIp = 'http://19.130.169.82/environment/gis'
    mapGeoserverIp = 'http://19.130.169.82/environment/gis/gis-proxy/proxy/fsprod1'
    mapTokenIp = 'http://19.130.169.82/environment/gis/gis-proxy/token/accessToken'
    break
  default:
    LoginUrl = `http://19.130.169.126/fszhsl/#/login`
    HttpUrl = `/webDataApi`
    // HttpUrl = `http://19.130.169.133/webDataApi`
    mapServiceIp = 'http://19.130.169.133/environment/gis'
    mapGeoserverIp = 'http://19.130.169.133/environment/gis/gis-proxy/proxy/fsprod1'
    mapTokenIp = 'http://19.130.169.133/environment/gis/gis-proxy/token/accessToken'
    break
}

// 后台数据返回成功标识
export const ERR_OK = 200

// 登陆超时标识
export const ERR_TIMEOUT = 402

// 访问后台传的token值
export const Options = () => {
  const obj = getStorage(tokenStorageKey) || {}

  return {
    headers: {
      'token': obj.token
    }
  }
}

// 访问地图传的token值
export const MapOptions = () => {
  const obj = getStorage(mapTokenStorageKey) || {}

  return obj.token
}

// console.log(MD5(`${MD5('12345678910')}@${MD5('Gykj@9527')}`))
export const UserCheck = () => {
  const telphone = getStorage(telphoneStorageKey)
  const username = getStorage(userNameStorageKey)

  const token = MD5(`${telphone}@${username}`)
  // console.log(MD5(`${MD5('12345678910')}@${MD5('Gykj@9527')}`))

  // return token === 'be932ae1213206d40fdfbdacfeb870d4'

  return true
}
